package com.wang.util;

import org.springframework.jms.annotation.JmsListener;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Component;

/**
 * @Classname Consumer
 * @Description TODO
 * @Date 2024/5/27 12:03
 * @Created by pc
 */
@Component
public class Consumer {
    /**
     * 监听Queue队列，queue类型
     */
    @JmsListener(destination = "springboot.queue",containerFactory = "jmsQueueListenerContainerFactory")
    public void receiveQueue(String text) {
        System.out.println(this.getClass().getName() + "-->收到的报文为:" + text);
    }

    /**
     * 监听Topic队列，topic类型，这里containerFactory要配置为jmsTopicListenerContainerFactory
     */
    @JmsListener(destination = "springboot.topic",
            containerFactory = "jmsTopicListenerContainerFactory")
    public void receiveTopic(String text) {
        System.out.println(this.getClass().getName() + "-->收到的报文为:" + text);
    }

    /*消费者消费之后回复消息*/
    @JmsListener(destination = "springboot.replyQueue",containerFactory ="jmsQueueListenerContainerFactory")
    @SendTo("replyTo.queue")
    public String receiveQueueReply(String text){
        System.out.println(this.getClass().getName() + "-->收到的报文为：" + text);
        return "回复的信息为：" + text;
    }
}
